package com.li.test.model5;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 - 消息队列的配置类
 */
@Configuration
public class RabbitConfigModel5 {

    //添加一个交换机
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange("topic.exchange");
    }

    //添加两个队列
    @Bean
    public Queue topicQueue1() {
        return new Queue("topic.queue1");
    }

    @Bean
    public Queue topicQueue2() {
        return new Queue("topic.queue2");
    }

    //绑定队列和交换机
    @Bean
    public Binding topicBinding1(Queue topicQueue1, TopicExchange topicExchange) {
        //路由键使用通配符
        return BindingBuilder.bind(topicQueue1).to(topicExchange).with("china.*");
    }

    @Bean
    public Binding topicBinding2(Queue topicQueue2, TopicExchange topicExchange) {
        //路由键使用通配符
        return BindingBuilder.bind(topicQueue2).to(topicExchange).with("#.news");
    }




    /**
     * 消息序列化成JSON字符串
     */
//    @Bean
//    public MessageConverter messageConverter() {
//        return new Jackson2JsonMessageConverter();
//    }
}